package com.church.daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.church.dao.MusicDao;
import com.church.db.Music;

public class MusicDaoImpl extends HibernateDaoSupport implements MusicDao {

	@Override
	public String add(Music music) {
		this.getHibernateTemplate().save(music);
		return "success";
	}

	@Override
	public String update(Music music) {
		this.getHibernateTemplate().update(music);
		return "success";
	}

	@Override
	public String remove(Music music) {
		this.getHibernateTemplate().delete(music);
		return "success";
	}

	@Override
	public Music findById(long id) {
		List<Music> list = this.getHibernateTemplate().find(
				"from Music as mu where mu.id=" + id);
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public Music findByName(String name) {
		List<Music> list = this.getHibernateTemplate().find(
				"from Music as mu where mu.name='" + name + "'");
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Music> getList() {
		List<Music> list = this.getHibernateTemplate().find("from Music where state!='3'");
		return list;

	}

}
